<template>
  <div class="content-container">
    <div class="header">
      <i
        v-if="!isCollapse"
        class="el-icon-s-fold"
        @click="changefold"
        :key="1"
      ></i>
      <i v-else class="el-icon-s-unfold" @click="changefold" :key="2"></i>
      <div class="personinfo">
        <span>{{ username }}</span>
        <i class="el-icon-switch-button" @click="logout"></i>
      </div>
    </div>
    <div class="content">
      <router-view :key="index" @changekey="changekey"></router-view>
    </div>
  </div>
</template>

<script>
export default {
  name: "",
  data() {
    return {
      username: "",
      index: 1,
    };
  },
  props: {
    isCollapse: {
      type: Boolean,
    },
  },
  methods: {
    changefold() {
      this.$emit("changefold");
    },
    changekey() {
      this.index += 1;
    },
    logout() {
      let username = localStorage.getItem("username");
      this.$Toast({
        content: username + "再见，欢迎下次使用！",
        type: "success",
      });
      setTimeout(() => {
        localStorage.clear();
        this.$router.push("/login");
      }, 3000);
    },
  },
  mounted() {
    //更新个人信息
    let user = localStorage.getItem("username");
    this.username = user;
  },
};
</script>

<style lang="less" scoped>
.header {
  color: #fff;
  height: 60px;
  line-height: 60px;
  background-color: rgb(84, 92, 100);
  i {
    font-size: 24px;
    cursor: pointer;
    &:hover {
      color: rgb(255, 208, 75);
    }
  }
  .personinfo {
    float: right;
    margin-right: 20px;
    span {
      display: inline-block;
      font-size: 16px;
      margin-right: 10px;
      height: 60px;
      line-height: 60px;
    }
  }
}
.content {
  margin: 20px;
}
</style>
